      <div class="templatemo-content-wrapper">
        <div class="templatemo-content">
         <ul class="nav nav-tabs mytabs">
         	 <li class="active"><a href="<?=site_url()?>/material/add">添加配方</a></li>
		  	 <li><a href="<?=site_url()?>/material/index">配方列表</a></li>
		  </ul>
          <div class="row">
            <div class="col-md-12">
              <div class="table-responsive">
                 <form role="form" id="templatemo-preferences-form" onsubmit="return false;">
                   <div class="row">
                 	 <div class="col-md-6 margin-bottom-15">
	              		<label for="firstName" class="control-label">配方图片</label>
	              		<input class="file-" type="file"  id="img" name="Filedata"/>
                		<input id="pic" name="pic" type="hidden" class="input" value="">
                		<img id="img_product" src="1.pic" width="50px;"  height="50px;"/>
                	</div>
                  </div>
                  <div class="row">
                  	<div class="col-md-6 margin-bottom-15">
                    	<label for="firstName" class="control-label">配方名称</label>
                    	<input type="text" class="form-control" id="name" value="">                  
                  	</div>
                  	<div class="col-md-6 margin-bottom-15">
                    	<label for="lastName" class="control-label">单位</label>
                    	<input type="text" class="form-control" id="unit" value="克">                 
                 	</div>
                  </div>
	              <div class="row templatemo-form-buttons">
	                <div class="col-md-12">
	                  <button type="submit" class="btn btn-primary" id="submit_btn">添加</button>
	                </div>
               	  </div>
                </form>
              </div>
            </div>
          </div>
        </div>
      </div>
<script>
	$(document).ready(function() {
		$('#img').ajaxfileupload({
				'action' : '<?php echo site_url('up/up_pic')?>',
				'params' : {
					'path' : 'product/pic'
				},
				onStart: function() {
					
				},
				'onComplete' : function(response) {
					if ( typeof response === 'string') {
						var files = response.replace(/\\/g, '/');
						$("#img_product").attr("src",'http://7xj0kd.com2.z0.glb.qiniucdn.com/'+files);
						$("#pic").val(files);
						alert("上传成功！");
					} else {
						alert("上传的文件格式不正确");
					}
				}
			});
          
		$("#submit_btn").click(function() {
			var image = $("#pic").val();
			var name = $("#name").val();
			var unit = $("#unit").val();

			if(name == ''){
				alert('名字不能为空')
				return;
			}
			
			$.ajax({
				url : '<?php echo site_url('material/save')?>',
				type : "post",
				async : false,
				data : {
					'image' : image,
					'name' : name,
					'unit' : unit
				},
				dataType : "json",
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						window.location.reload();
					}else{
						alert(data.msg);
					}
				}
			});
		});
	}); 
</script>